package com.czone.myfacebook;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import org.json.JSONException;
import org.json.JSONObject;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.widget.ImageView;

public class FaceBookData {
    /*
     * 
     * { "id": "1374062322_10200352055748702", "from": { "name":
     * "HyoYong Jeong", "id": "1374062322" }, "created_time":
     * "2013-07-18T12:46:31+0000" },
     */
    private static final String TAG = "FaceBookData";
    HashMap<String, String> mHash = new HashMap<String, String>();
    ImageView mImageView;

    public FaceBookData() {
    }

    public void setObject(String param, String data) {
        if (mHash.containsKey(param)) {
            mHash.remove(param);
        }
        
        //CONVERT QUALITY PICTURE IMAGE 
        if(Define.INDEX_PICTURE.equals(param)) {
            data = Utils.convertImageQuality(data);
        }
        
        mHash.put(param, data);
    }

    public String getObject(String param) {
        if (Define.INDEX_FROM_ID.equals(param)) {
            return getFromID();
        } else if (Define.INDEX_FROM_NAME.equals(param)) {
            return getFromName();
        }

        return mHash.get(param);
    }

    private String getFromID() {
        String reStr = null;
        try {
            JSONObject dataObject = new JSONObject(mHash.get(Define.INDEX_FROM));
            reStr = dataObject.getString("id");
        } catch (JSONException e) {
            CLog.e(TAG, "e = " + e);
        }
        return reStr;
    }

    private String getFromName() {
        String reStr = null;
        try {
            JSONObject dataObject = new JSONObject(mHash.get(Define.INDEX_FROM));
            reStr = dataObject.getString("name");
        } catch (JSONException e) {
            CLog.e(TAG, "e = " + e);
        }
        return reStr;
    }

    @Override
    public String toString() {
        if (0 == mHash.size()) {
            CLog.e(TAG, "mHash empty ==============================");
            return "";
        }

        String reStr = "";
        for (Entry<String, String> entry : mHash.entrySet()) {
            if (null != entry.getKey()) {
                reStr += entry.getKey();
                reStr += " = ";
                reStr += entry.getValue();
                reStr += "\n";
            }
        }

        return reStr;
    }
}